package com.lemon.smartsafetynew.ui.fragment.hidden;

import android.os.Bundle;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenDownloadVo;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenProcessItemVo;
import com.lemon.smartsafetynew.net.services.SafeHiddenServices;
import com.lemon.smartsafetynew.ui.activity.hidden.SafeHiddenProcessDetailActivity;
import com.lemon.smartsafetynew.ui.adapter.hidden.SafeHiddenProcessListAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Andrew on 2017/9/11.
 */

public class SafeHiddenProcessTabTwoContentFragment extends BasePullToRefreshFragment<SafeHiddenProcessItemVo, List<SafeHiddenProcessItemVo>>
        implements RecyclerTClickListener<SafeHiddenProcessItemVo> {

    private static SafeHiddenDownloadVo safeHiddenDownloadVo;

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();
        if(bundle != null) {
            if(bundle.containsKey(KeyConstants.KEY_SAFE_HIDDEN_DOWNLOAD_VO)) {
                safeHiddenDownloadVo = (SafeHiddenDownloadVo) bundle.getSerializable(KeyConstants.KEY_SAFE_HIDDEN_DOWNLOAD_VO);
            }
        }
    }

    public static SafeHiddenProcessTabTwoContentFragment newInstance(SafeHiddenDownloadVo data) {

        Bundle args = new Bundle();
        args.putSerializable(KeyConstants.KEY_SAFE_HIDDEN_DOWNLOAD_VO, data);

        SafeHiddenProcessTabTwoContentFragment fragment = new SafeHiddenProcessTabTwoContentFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onPullRefresh() {

        LemonRequestParams params = new LemonRequestParams("");
        params.put("danger_id", safeHiddenDownloadVo.getId());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);

        SafeHiddenServices
                .init()
                .getSafeHiddenHandleRecords(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {

        LemonRequestParams params = new LemonRequestParams("");
        params.put("danger_id", safeHiddenDownloadVo.getId());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);

        SafeHiddenServices
                .init()
                .getSafeHiddenHandleRecords(RefreshType.LOAD_MORE, params);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<SafeHiddenProcessItemVo> getLemonAdapter() {
        return new SafeHiddenProcessListAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_GET_SAFE_HIDDEN_RECORDS;
    }

    /**
     * 查看详情
     * @param data
     * @param position
     */
    @Override
    public void onItemClick(SafeHiddenProcessItemVo data, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_SAFE_HIDDEN_PROCESS_ITEM_VO, data);
        bundle.putSerializable(KeyConstants.KEY_SAFE_HIDDEN_DOWNLOAD_VO, safeHiddenDownloadVo);
        UIHelper.showActivity(getmContext(), bundle, SafeHiddenProcessDetailActivity.class);
    }


}
